//
//  NearShopCell.m
//  FKGW
//
//  Created by song ce on 2017/2/17.
//  Copyright © 2017年 song ce. All rights reserved.
//

#import "NearShopCell.h"
#import "ScanAllViewController.h"
#import "OSSHelper.h"
@implementation NearShopCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.shopIcon.layer.cornerRadius = 18.5;
    self.shopIcon.layer.masksToBounds = YES;
    _iamgeV= [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, Main_Screen_Width, 200)];
//    _iamgeV.image = [UIImage imageNamed:@"photo_shangchang"];
//    _iamgeV.contentMode = UIViewContentModeScaleAspectFill;
    [self.contentView insertSubview:_iamgeV atIndex:0];
   
}
//快速浏览
- (IBAction)live:(id)sender {
    ScanAllViewController *scanAllCtrl = [[ScanAllViewController alloc]init];
    scanAllCtrl.isModel = YES;
    scanAllCtrl.count = 2;
    scanAllCtrl.storeId = _model.id;
      BaseNavigationViewController *navi = [[BaseNavigationViewController alloc]initWithRootViewController:scanAllCtrl];
    [[self  baseNearViewController] presentViewController:navi animated:YES completion:nil];
}

-(void)setIsLive:(BOOL)isLive{
    
    if(isLive){
        self.liveLabel.hidden = NO;
        self.liveImageV.hidden = NO;
    }else{
        self.liveLabel.hidden = YES;
        self.liveImageV.hidden = YES;
    }
}
-(void)setIsShowRightBottonButn:(BOOL)isShowRightBottonButn{
    if(isShowRightBottonButn){
        self.liveButton.hidden =NO;
    }else{
         self.liveButton.hidden =YES;
    }
}
-(void)setIsShowDistance:(BOOL)isShowDistance{
    if(isShowDistance){
        self.distance.hidden =NO;
    }else{
        self.distance.hidden =YES;
    }
}

-(void)setModel:(NearShopModel *)model{
    _model = model;
   
   
    self.shopLocation.text = _model.address;
       //距离相关处理
    NSInteger distance =[_model.distance integerValue];
    if( distance<1000){
         self.distance.text = [NSString stringWithFormat:@"距离%@米",_model.distance];
    }else{
        double dis = [_model.distance doubleValue]/1000;
        self.distance.text = [NSString stringWithFormat:@"距离%.2fkm",dis];
    }
    self.isLive = [_model.isLive boolValue];
    
    if(_model.isMarket){
        self.shopIcon.hidden = YES;
        self.shopDescreption.hidden = YES;
        self.shaopNameLabel.hidden = YES;
        self.marketNameLabel.hidden = NO;
        self.marketNameLabel.text = _model.name;
     
    }else{
        self.marketNameLabel.hidden = YES;
         self.shaopNameLabel.text = _model.name;
        if([_model.introduce isKindOfClass:[NSNull class]]){
            self.shopDescreption.text = @"'";
        }else{
            self.shopDescreption.text = _model.introduce;
        }
        [[OSSHelper sharedHelper]OSSDownLoadWithObjectKey:_model.storeHeader xOssProcess:[NSString stringWithFormat:@"image/resize,m_fill,w_%d,h_%d",37,37]  downLoadBlock:^(NSData *data) {
            dispatch_async(dispatch_get_main_queue(), ^{
                self.shopIcon.image= [UIImage imageWithData:data];
            });
        }];
    }
    
    NSString *pic;
    if(_model.storePic.length){
        pic = _model.storePic;
    }else{
        pic = _model.pic;
    }
     self.iamgeV.image = [UIImage imageNamed:@"dianpu_msg"];
    [[OSSHelper sharedHelper]OSSDownLoadWithObjectKey:pic xOssProcess:[NSString stringWithFormat:@"image/resize,m_fill,w_%d,h_%d",(int)(Main_Screen_Width),200]  downLoadBlock:^(NSData *data) {
        dispatch_async(dispatch_get_main_queue(), ^{
            self.iamgeV.image= [UIImage imageWithData:data];
        });
    }];
//    if(!_model.storePic.length||![_model.storePic containsString:@"."]){
//        self.iamgeV.image = [UIImage imageNamed:@"dianpu_msg"];
//    }else{
//          }
    
  
}


- (BaseNearViewController*)baseNearViewController{
    UIResponder *next = self.nextResponder;
    while (next!=nil) {
        if([next isKindOfClass:[BaseNearViewController class]]){
            return (BaseNearViewController*)next;
        }
        next = next.nextResponder;
    }
    return nil;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
